package cn.xscrum.vtsp.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.xscrum.common.utils.ServletUtils;
import cn.xscrum.wxapp.common.ApiBaseController;
import cn.xscrum.wxapp.common.ApiResult;

public class BaseMobileController extends ApiBaseController
{
	protected final Logger logger = LoggerFactory.getLogger(BaseMobileController.class);
	/**
	 * 获取request
	 */
	public HttpServletRequest getRequest()
	{
		return ServletUtils.getRequest();
	}
	
	/**
	 * 获取response
	 */
	public HttpServletResponse getResponse()
	{
		return ServletUtils.getResponse();
	}

	/**
	 * 获取session
	 */
	public HttpSession getSession()
	{
		return getRequest().getSession();
	}

	/**
	 * 返回成功消息
	 */
	public ApiResult success(String message)
	{
		return ApiResult.success(message);
	}

	/**
	 * 返回成功数据
	 * 
	 * @return 成功消息
	 */
	public static ApiResult success(Object data)
	{
		return ApiResult.success("操作成功", data);
	}

	/**
	 * 返回失败消息
	 */
	public ApiResult error(String message)
	{
		return ApiResult.error(message);
	}

	/**
	 * 返回成功
	 */
	public ApiResult success()
	{
		return ApiResult.success();
	}

	/**
	 * 返回失败消息
	 */
	public ApiResult error()
	{
		return ApiResult.error();
	}
	
	/**
	 * 通过Session缓存
	 * @param key
	 * @param value
	 */
	public void setValue(String key,String value)
	{
		getSession().setAttribute(key, value);
	}
	
	/**
	 *  通过Session值
	 * @param key
	 * @return
	 */
	public String getValue(String key)
	{
		return (String)getSession().getAttribute(key);
	}
}
